-
Notifications
You must be signed in to change notification settings - Fork 56
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Int
- two's complement
#695
Conversation
FYI: local benchmark results @ b23483d
|
@tarcieri Re: proptest |
@erik-3milabs if you make such an issue yourself, you can manage the task list in the description. Otherwise you'll be blocked on me to do updates. |
You'll likely need to expand the nearly hundred comments in the middle of the thread, which is all the more reason to get this merged. I'll try to do another pass soon. |
@erik-3milabs The carry is non-zero also when Int::MIN is being negated, it's Word::ONE in this case. Or at least it should be, right? |
@lleoha IIRC, the negation map is Applying this to
What am I missing / what is your reasoning for saying the carry should equal 1? |
Let's say the limb is 8 bit. So the min is -128. Then neg(-128) = 128, which can only be represented with two limbs in signed arithmetic. |
Fourth attempt to write this. I investigated this issue a bit, and I think I figured out we were both mistaken. As it turns out, the devil is in the tiniest of details:
You are correct that that addition overflows, but I don't think your "hence" is correct. When operating on signed integers, the IMU, For unsigned integers, the whole concept of "negation" is vague anyway. There, I decided to stick with "carrying_neg" and have it carry when "negating" zero, as that seems to make the most sense. Thank you for persisting! Let me know what you think of the patch I wrote. |
Hi @erik-3milabs . I kind of agree, It boils down to the definition. Now back our use case. Which should it be? I have no idea :). But since we have a different type for signed and unsigned arithmetic, it makes more sense to be like a overflow or extend. What you're proposing is more like overflow, what I'm proposing is more like extend, neither is carry :). Not sure which route is a "correct" one though. |
@lleoha thanks for the elaboration! I think we are (very close) to (finally 😄) being on the same page. For unsigned ( For signed ( |
Topic
Adding
Int
support (see #624/#700)To decide on sign-and-magnitude (#694) vs. two's complement, I whipped up a quick two's complement implementation of the basic add/sub/mul/div operations. It's not perfect yet; I'm just curious to see how it compares to #694.